(deftemplate person
    (slot name)
    (slot max-distance)
    (slot hobby)
    (slot final-grade)
    (slot tax-free-education-only)
)

(deftemplate specialty
    (slot name)
    (slot distance)
    (slot minimum-admission-grade-without-taxes)
    (slot minimum-admission-grade)
)

(deftemplate hobby-recommendation
    (slot hobby)
    (slot specialty)
)

(deftemplate person-recommendation
	(slot name)
	(slot specialty)
)

(deffacts faculties
    (specialty  
        (name "Informatica Timisoara")
        (distance 60)
        (minimum-admission-grade-without-taxes 8.5)	 
        (minimum-admission-grade 6.7)
    )
    (specialty
        (name "Matematica Timisoara")
		(distance 60)
        (minimum-admission-grade-without-taxes 7.0)
        (minimum-admission-grade 6.0)    
    )
    (specialty
        (name "Politehnica Timisoara")
		(distance 60)
        (minimum-admission-grade-without-taxes 9.0)
        (minimum-admission-grade 8.0)    
    )    
    (specialty
        (name "Chineza-Japoneza Bucuresti")
		(distance 660)
        (minimum-admission-grade-without-taxes 6.5)
        (minimum-admission-grade 5.5)    
    ) 
    (specialty
        (name "Limbi Straine Aplicate Timisoara")
        (distance 60)
        (minimum-admission-grade-without-taxes 5.5)
        (minimum-admission-grade 5.0)
    )
    (specialty
        (name "Limba si Literatura Romana Timisoara")
        (distance 60)
        (minimum-admission-grade-without-taxes 5.0)
        (minimum-admission-grade 5.0)
    )
    (specialty
        (name "Psihologie Timisoara")
        (distance 60)
        (minimum-admission-grade-without-taxes 7.5)
        (minimum-admission-grade 6.0)
    )
    (specialty
        (name "Academia Navala Constanta")
        (distance 800)
        (minimum-admission-grade-without-taxes 6.5)
        (minimum-admission-grade 5.0)
    )
    (specialty
        (name "Cibernetica Bucuresti")
        (distance 660)
        (minimum-admission-grade-without-taxes 9.0)
        (minimum-admission-grade 7.0)
    )
    (specialty
        (name "Forte Terestre Sibiu")
        (distance 300)
        (minimum-admission-grade-without-taxes 6.4)
        (minimum-admission-grade 5.0)
    )
    (specialty
        (name "Academia de Politie Bucuresti")
        (distance 660)
        (minimum-admission-grade-without-taxes 5.0)
        (minimum-admission-grade 5.0)
    ) 
)

(deffacts persons
    (person
	    (name "Decebal")
   		 (max-distance 1000)
    	(hobby guns)
    	(final-grade 6.0)
	    (tax-free-education-only TRUE)
    )
    (person
	    (name "Traian Basescu")
   		 (max-distance 1000)
    	(hobby boats)
    	(final-grade 5.0)
	    (tax-free-education-only FALSE)
    )
    (person
    	(name "Maria")
        (max-distance 800)    
        (hobby foreign-languages)
        (final-grade 10.0)
        (tax-free-education-only FALSE)
    )
    (person
        (name "Arnold")
        (max-distance 400)
        (hobby guns)
        (final-grade 7.0)
        (tax-free-education-only TRUE)
     )
    (person
        (name "Garcea")
        (max-distance 800)
        (hobby law-enforcement)
        (final-grade 5.0)
        (tax-free-education-only TRUE)
     )
    (person
        (name "Ana")
        (max-distance 200)
        (hobby literature)
        (final-grade 7.0)
        (tax-free-education-only TRUE)
     )
    (person 
        (name "George")
        (max-distance 600)
        (hobby programming)
        (final-grade 7.0)
        (tax-free-education-only FALSE)
    )
    (person
        (name "Radu")
        (max-distance 100)
        (hobby electronics)
        (final-grade 8.5)
        (tax-free-education-only FALSE)
        )
)
    
(deffacts hobby-recommendations
    (hobby-recommendation
	    (hobby electronics)
    	(specialty "Politehnica Timisoara")
    )
	(hobby-recommendation
        (hobby guns)
        (specialty "Forte Terestre Sibiu")
	)
    (hobby-recommendation
        (hobby law-enforcement)
        (specialty "Academia de Politie Bucuresti")    
    )   
    (hobby-recommendation
        (hobby programming)
        (specialty "Informatica Timisoara"
     )
        )
    (hobby-recommendation
         (hobby programming)
         (specialty "Cibernetica Bucuresti")
    )
    (hobby-recommendation
         (hobby literature)       
		 (specialty "Limba si Literatura Romana Timisoara")
    )
    (hobby-recommendation
         (hobby foreign-languages)
         (specialty "Limbi Straine Aplicate Timisoara")
    )
    (hobby-recommendation
         (hobby foreign-languages)
         (specialty "Chineza-Japoneza Bucuresti")
    )
)
               
(defrule recommend-specialty
     (hobby-recommendation (hobby ?h) (specialty ?s))
     (specialty (name ?s1&?s) (distance ?d) (minimum-admission-grade ?mag) (minimum-admission-grade-without-taxes ?magwot))
  	(person
        (name ?n)
       (max-distance ?md&:(< ?d ?md))
       (hobby ?h1&?h)
       (tax-free-education-only ?tfo)
        (final-grade ?f&:(and (eq ?tfo TRUE) (> ?f ?magwot))|:(and (eq ?tfo FALSE) (> ?f ?mag)))
 ;       (final-grade ?f&:(?tfo FALSE)&:(> ?f ?mag))
    )
     =>
    (assert (person-recommendation (name ?n) (specialty ?s)))
)
    
(defrule print-results
    (person-recommendation (name ?n) (specialty ?s))
    =>
    (printout t "Recommendation: " ?n " => " ?s crlf)
)
    
    
(reset)
(run)